package part19_状态模式_抽奖;

/**
 * @ClassName: RaffleActivity
 * @Author: AllenSun
 * @Date: 2020/3/9 21:17
 */
public class RaffleActivity {
    //表示活动的状态，是变化
    State state= null;
    //奖品的数量
    int count=0;
    //奖品的属性，表示四种状态
    State noRaffleState=new NoRaffleState(this);
    State canRaffleState=new CanRaffleState(this);
    State dispenseState=new DispenseState(this);
    State dispenseOutState=new DispenseOutState(this);

    public RaffleActivity(int count) {
        //初始化状态为不能抽奖
        this.state=getNoRaffleState();
        //初始化奖品的数量
        this.count = count;
    }

    //扣分，调用当前状态的debuctMoney
    public void debuctMoney(){
        state.deductMoney();
    }

    public void raffle(){
        if(state.raffle()){
            state.despendePrize();
        }
    }

    public State getNoRaffleState() {
        return noRaffleState;
    }

    public void setNoRaffleState(State noRaffleState) {
        this.noRaffleState = noRaffleState;
    }

    public State getCanRaffleState() {
        return canRaffleState;
    }

    public void setCanRaffleState(State canRaffleState) {
        this.canRaffleState = canRaffleState;
    }

    public State getDispenseState() {
        return dispenseState;
    }

    public void setDispenseState(State dispenseState) {
        this.dispenseState = dispenseState;
    }

    public State getDispenseOutState() {
        return dispenseOutState;
    }

    public void setDispenseOutState(State dispenseOutState) {
        this.dispenseOutState = dispenseOutState;
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public int getCount() {
        int curCount=count;
        --count;
        return curCount;
    }

    public void setCount(int count) {
        this.count = count;
    }
}
